/**
 * Created by lwy on 2017/8/30.
 */

var details;
var page = 1;

$(function () {

    $.ajax({
        url: '/crm/inventoryC/getInventoryDetails.json',
        dataType: 'json',
        data: {
            token: localStorage.getItem('crmtoken'),
            id: $('#idBox').html(),
        },
        success: function (data) {
            if (data.code == -1) {
                window.parent.location.href = "/crm/login.jsp";
            }
            if (data.code == 0) {
                alert(data.msg);
            }
            if (data.code == 1) {
                var data = data.datas;
                $('#inventory').val(data.inventory);
                $('#idBox').val(data.id);
                $('#name').val(data.name);
                $('#sumary').val(data.abbreviation);
                $('#goodsExplain').val(data.goodsExplain);
                $('#memberPrice').val(data.memberPrice);
                $('#addstate').val(data.goodsState);
                $('#mainImg').attr('src', data.mainImg);
                $('#detailImg').append(data.detailsImg);
                $('#target').val(data.detailsImg);
                $('#content').html(data.detailsImg);
                $('#isWarranty').val(data.isWarranty);
                $('#isImie').val(data.isImie);
                $('#propertiesName').val(data.propertiesName);

                $('#warrantyPeriod').val(data.warrantyPeriod);

                getLogList();
            }
        }
    })
})

function getLogList() {

    $.ajax({
        type: 'POST',
        url: '/crm/inventoryC/getLogList.json?v=' + new Date().getTime(),
        dataType: "json",   //参数格式为json
        data: {
            token: localStorage.getItem('crmtoken'),
            page:page,
            inventoryId: $('#idBox').html(),
            typeValue: $('#typeValue2').val(),
            inventorySourceValue: $('#inventorySourceValue2').val(),
        },
        success: function (data) {
            if (data.code == 0) {
                alert(data.msg);
            } else if (data.code == -1) {
                window.parent.location.href = "/crm/login.jsp";
            } else if (data.code == 1) {
                $('#record').html(data.recordsTotal);
                $('#inventoryLogtable').empty();
                $.each(data.datas, function (index, obj) {
                    var tdName = $("<tr><td>" + obj.id + "</td>");
                    tdName.append($("<td>" + obj.code + "</td>"))
                    tdName.append($("<td>" + obj.inventorySource + "</td>"))
                    tdName.append($("<td>" + obj.changeNum + "</td>"));
                    tdName.append($("<td>" + obj.userName + "</td>"));
                    tdName.append($("<td>" + obj.createTime + "</td>"));
                    tdName.append($("<td>" + obj.remark + "</td>"));
                    $('#inventoryLogtable').append(tdName);
                });
                $(".pagination").createPage({
                    totalPage:data.totalPage,
                    currPage:data.pageNow,
                    pageCount:data.pageNow,
                    turndown:'true',
                    backFn:function(p){
                        page=p;
                        getLogList();
                    }
                });

            }

        }
    });

}

//查询
$('#refer').click(function(){
    page=1;
    getLogList();
})



